### LISTS OF TYPE INDICES BY INDIV CHAR'S

### NOTE: Here "Z" denotes characteristics of the researchers.

# Numbers of experienced authors by Z:

N_Z <- as.list(tapply(counts, types[,"Z"], sum))

# All "feasible" (observed or residual) types:

feasible_idx <- NULL

for (z in as.numeric(names(table(types[,1]))) )  {
	feasible_idx <- c(feasible_idx,
	list(which(types[,1]==z))
	)
}
names(feasible_idx) <- levels(Z)[as.numeric(names(table(types[,1])))]

# Check:

all(sort(unlist(feasible_idx) ) == 1:N_types)

# Isolated types:

isolated_idx <- feasible_idx

for (z in names(isolated_idx) )  {
	isolated_idx[[z]] <- which(levels(Z)[types[,"Z"]] == z & N_t[,1] == 0)
}

# Purely residual categories:

residual1_idx <- feasible_idx

for (z in names(residual1_idx) )  {
	residual1_idx[[z]] <- which(levels(Z)[types[,"Z"]] == z &  is.na(N_t[,1]) & is.na(types[,2]) )
}

# Combined residual categories:

residual2_idx <- feasible_idx

for (z in names(residual2_idx) )  {
	residual2_idx[[z]] <- which(levels(Z)[types[,"Z"]] == z & !is.na(N_t[,1]) & is.na(types[,2]) )
}

# Format names for MATLAB:

names(feasible_idx) <- paste0("Z",names(feasible_idx) )
names(isolated_idx) <- paste0("Z",names(isolated_idx) )
names(residual1_idx) <- paste0("Z",names(residual1_idx) )
names(residual2_idx) <- paste0("Z",names(residual2_idx) )

names(N_Z) <- names(feasible_idx)

# Clean up:

rm(z)
